package com.shure.encrypt.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.shure.encrypt.encrypt.EncryptService;
import com.shure.encrypt.plugin.ParameterInterceptor;
import com.shure.encrypt.plugin.ResultInterceptor;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class StorageConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public MybatisPlusInterceptor mybatisPlusInterceptor(StorageEncryptProperties properties, EncryptService encryptService) {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new ParameterInterceptor(properties, encryptService));
        return interceptor;
    }

    @Bean
    @ConditionalOnMissingBean
    public ResultInterceptor getResultInterceptor(StorageEncryptProperties properties, EncryptService encryptService) {
        return new ResultInterceptor(properties, encryptService);
    }
}
